#ifndef __H_PUBLIC_H__
#define __H_PUBLIC_H__
#include <sys/socket.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <strings.h> //for bzero
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <memory>
#include <netinet/tcp.h>
#include <functional>
#include <chrono>
using namespace std;
using namespace chrono;

static const char*  SERVER_IP				= "127.0.0.1";
static const int    SERVER_PORT				= 19527;
static const int	READ_BUFFER_LENGTH		= 1024;
static const int	EPOLL_EVENT_COUNT		= 500;
static const int	INIT_EVENT_LIST_SIZE	= 16;
static const int	MICRO_SECONDS_PER_SECOND = 1000 * 1000;

static string debug_time()
{
	struct timeval tv;
	bzero(&tv, sizeof(timeval));
	gettimeofday(&tv, NULL);
	int64_t pre_seconds = tv.tv_sec;
	pre_seconds = pre_seconds * 1000000 + tv.tv_usec;

	time_t seconds = static_cast<time_t>(pre_seconds / MICRO_SECONDS_PER_SECOND);
	struct tm tm_time;
	bzero(&tm_time, sizeof(tm));
	gmtime_r(&seconds, &tm_time);

	int microseconds = static_cast<int>(pre_seconds % MICRO_SECONDS_PER_SECOND);

	char buf[128] = { 0, };
	snprintf(buf, sizeof(buf), "%4d%02d%02d %02d:%02d:%02d.%06d >> ",
		tm_time.tm_year + 1900, tm_time.tm_mon + 1, tm_time.tm_mday,
		tm_time.tm_hour+8, tm_time.tm_min, tm_time.tm_sec,
		microseconds);

	return buf;
}

#define RUN_TRACE do { cout << debug_time() << __PRETTY_FUNCTION__ << endl; } while (0);



#endif // __H_PUBLIC_H__